<?php
/**
 * Created by 张彪.
 * User: 小马出行
 * Date: 2018/1/16
 * Time: 16:57
 */
namespace app\inter\model;
use \think\Model;
use think\Db;

class DriverBankModel extends InterBase
{
    public function getDriverBank($map,$field='a.*',$flag=true,$page=1,$limit=10,$config='')
    {
        $config = $config?:$this->config;
        return $flag ? Db::connect($config)->name('driver_bank a')->join(['xm_driver_base'=>'c'],' a.driver_id=c.driver_id','LEFT')
            ->join(config('inner_db')['database'].'.xm_bank b','b.id=a.bank_id','LEFT')
            ->where($map)->field($field)->page($page,$limit)->select()
            : Db::connect($config)->name('driver_bank a')->join(['xm_driver_base'=>'c'],' a.driver_id=c.driver_id','LEFT')
                ->join(config('inner_db')['database'].'.xm_bank b','b.id=a.bank_id','LEFT')
                ->where($map)->field($field)->find();
    }

    public function addDriverBank($data,$config='')
    {
        $config = $config?:$this->config;
        return Db::connect($config)->name('driver_bank')->insertGetId($data);
    }

    public function updateDriverBank($map,$data,$config='')
    {
        $config = $config?:$this->config;
        return Db::connect($config)->name('driver_bank')->where($map)->update($data);
    }
}